//
//  Location.m
//  TestAll
//
//  Created by zhaoguoying on 2018/3/9.
//  Copyright © 2018年 ZDHS. All rights reserved.
//

#import "RC.h"

@interface RC ()<RCIMUserInfoDataSource,RCIMGroupInfoDataSource,RCIMGroupUserInfoDataSource,RCIMGroupMemberDataSource,RCIMReceiveMessageDelegate>

@end

@implementation RC
singleton_implementation(RC)
-(void)_init{
    
    NSString *rongyunKey = @"sfci50a7sxzpi"; // 测试key
    rongyunKey = @"y745wfm8yhapv"; // 正式key
    
    [RCIM.sharedRCIM initWithAppKey:rongyunKey];
    RCIM.sharedRCIM.userInfoDataSource = self;
    RCIM.sharedRCIM.groupInfoDataSource = self;
    RCIM.sharedRCIM.groupUserInfoDataSource = self;
    RCIM.sharedRCIM.groupMemberDataSource = self;
    [RCIM sharedRCIM].receiveMessageDelegate = self;
    
//    [[RCCallClient sharedRCCallClient] setVideoOrientation:AVCaptureVideoOrientationPortrait]; //横屏设置
//    - (void)didChangeRotate:(NSNotification*)notice {
//        if ([[UIDevice currentDevice] orientation] == UIInterfaceOrientationPortrait
//            || [[UIDevice currentDevice] orientation] == UIInterfaceOrientationPortraitUpsideDown) {
//            //竖屏
//            [[RCCallClient sharedRCCallClient] setVideoOrientation:AVCaptureVideoOrientationPortrait];
//            
//        } else {
//            //横屏
//            if ([[UIDevice currentDevice] orientation] == UIInterfaceOrientationLandscapeLeft) {
//                [[RCCallClient sharedRCCallClient] setVideoOrientation:AVCaptureVideoOrientationLandscapeRight];
//            }else{
//                [[RCCallClient sharedRCCallClient] setVideoOrientation:AVCaptureVideoOrientationLandscapeLeft];
//            }
//            
//        }
//        
//    }
}
- (void)onRCIMReceiveMessage:(RCMessage *)message left:(int)left{
    NSLog(@"");
}
//- (void)setCurrentUserInfo {
//    //设置当前用户信息，用于显示自己的头像和昵称
//    RCUserInfo *userInfo = [[RCUserInfo alloc] initWithUserId:@"1" name:@"zhao" portrait:@"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1568875876191&di=2933bebe9b22899f59840c33b24a1f98&imgtype=0&src=http%3A%2F%2Fimg.mp.itc.cn%2Fupload%2F20161119%2F7205fcb7ca4149c1920c01524112cbd9_th.jpg"];
//    [RCIM sharedRCIM].currentUserInfo = userInfo;
//}

// 实现用户信息提供者的代理函数
- (void)getUserInfoWithUserId:(NSString *)userId completion:(void (^)(RCUserInfo *))completion {
    //开发者需要将 userId 对应的用户信息返回，下列仅为示例
    
    NSMutableArray *arr = NSMutableArray.array;
    for (int i=1; i<11; i++) {
        [arr addObject:[NSString stringWithFormat:@"%d",i]];
    }
    for (NSString *user in arr) {
        if ([userId isEqualToString:user]) {
            NSString *userName = [NSString stringWithFormat:@"用户%@",userId];
            RCUserInfo *userInfo = [[RCUserInfo alloc] initWithUserId:userId name:userName portrait:nil];// @"http://www.wengegroup.com/img/logo/LOGO_new.png"
            if (completion) {
                completion(userInfo);
            }
        }
    }
}
// 群组
-(void)getGroupInfoWithGroupId:(NSString *)groupId completion:(void (^)(RCGroup *))completion{
    if ([groupId isEqualToString:@"100"]) {
        RCGroup *group = RCGroup.new;
        group.groupId = @"100";
        group.groupName = @"群组测试";
        completion(group);
    }
}
// 群成员群名片
- (void)getUserInfoWithUserId:(NSString *)userId inGroup:(NSString *)groupId completion:(void (^)(RCUserInfo *))completion{
    if ([groupId isEqualToString:@"100"]) {
        RCUserInfo *user = RCUserInfo.new;
        user.userId = userId;
        user.name = [NSString stringWithFormat:@"用户%@",userId];
        completion(user);
    }
}
// 群成员
-(void)getAllMembersOfGroup:(NSString *)groupId result:(void (^)(NSArray<NSString *> *))resultBlock{
    if ([groupId isEqualToString:@"100"]) {
        resultBlock(@[@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9",@"10"]);
    }
}
@end
